import { Entity, PrimaryGeneratedColumn, Column, OneToOne, ManyToOne } from 'typeorm';
import { Family } from './Family';
import { Line } from './Line';

@Entity()
export class User {

  // PrimaryColumn
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 10 })
  firstName: string;

  @Column()
  lastName: string;

  @Column()
  age: number;

  @OneToOne(type => Family, family => family.user)
  family: Family;

  // cascade 设置为true，那么保存数据的时候，不用保存2次，保存了user，family也会自动保存
  // @OneToOne(type => Family, family => family.user, { cascade: true})
  // family: Family;

  @ManyToOne(type => Line, line => line.users)
  line: Line
}
